package org.hsieh.tr.explore.dbsource.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hsieh.tr.explore.annotation.TreeNodeChildren;
import org.hsieh.tr.explore.annotation.TreeNodeLabel;
import org.hsieh.tr.explore.dbsource.ISchemaEntity;
import org.hsieh.tr.explore.dbsource.ITableEntity;

/**
 * 
 * 
 *@author hsieh 234aini@gmail.com
 * 
 */
public class SchemaEntityImpl extends AbstractDBObj implements ISchemaEntity {

    private String name;

    private List<ITableEntity> tables;

    public boolean isDefault;

    public String tableCatalog;

    public void setName(String name) {
	this.name = name;
    }

    public String getName() {
	return name;
    }

    @TreeNodeLabel(image = "icons/db/tr_schema.png")
    public String displaySchema() {
	return "Schema " + getName();
    }

    @TreeNodeChildren
    public List<ITableEntity> getTables() throws SQLException {
	if (tables == null) {
	    tables = new ArrayList<ITableEntity>();
	}
	tables = findTables(this);
	return tables;
    }

    public boolean isDefault() {
	return isDefault;
    }

    public void setDefault(boolean isDefault) {
	this.isDefault = isDefault;
    }

    public String getTableCatalog() {
	return tableCatalog;
    }

    public void setTableCatalog(String tableCatalog) {
	this.tableCatalog = tableCatalog;
    }

    @Override
    public String toString() {
	return "SchemaEntityImpl [isDefault=" + isDefault + ", name=" + name
		+ ", tableCatalog=" + tableCatalog + "]";
    }

    @Override
    public void refresh() {
	tables = null;
	super.refresh();
    }

}
